<template>
    <div class="assets-info">
        <div class="base-box">
            <List header="+" footer="+" border>
                <ListItem>当前节操币余额: {{this.baseInfo.money}}</ListItem>
                <ListItem>历史充值节操币: {{this.baseInfo.allcharge}}</ListItem>
                <ListItem>历史消费节操币: {{this.baseInfo.allpay}}</ListItem>
            </List>
        </div>
        <div class="space-box">玩家节操币消费最近五条记录</div>
        <Table :columns="recordColumns" :data="recordData"></Table>
        <div class="space-box">玩家金币消费所有记录</div>
        <Table :columns="economyCol" :data="economyRecordList"></Table>
    </div>
</template>

<script>
    import Ajax from '../../Ajax'
    import common from '../../common'
    export default {
        name: "AssetsInfo",
        data() {
            return {
                baseInfo: {},
                recordColumns: [
                    {
                        title: '日期',
                        key: 'date'
                    },
                    {
                        title: '用途说明',
                        key: 'text'
                    },
                    {
                        title: '金额',
                        key: 'money'
                    }
                ],
                economyCol: [
                    {
                        title: 'ID',
                        key: 'id'
                    },
                    {
                        title: '时间',
                        key: 'date'
                    },
                    {
                        title: '金额',
                        key: 'amount'
                    },
                    {
                        title: '余额',
                        key: 'balance'
                    },
                    {
                        title: '操作',
                        key: 'operation'
                    },
                    {
                        title: '玩家',
                        key: 'player'
                    },
                    {
                        title: '类型',
                        key: 'type'
                    },
                    {
                        title: '命令',
                        key: 'command'
                    },
                    {
                        title: 'UID',
                        key: 'uid'
                    }
                ],
                recordData: [],
                economyRecordList: []
            }
        },
        mounted() {
            this.getMcrmbPlayerInfo()
            this.getMcrmbPlayerRecord()
            this.getPlayerAllEconomyRecord()
        },
        methods: {
            getMcrmbPlayerInfo() {
                let playerName = common.getCookie('playerName')
                if (!!!playerName) {
                    return
                }
                let param = new URLSearchParams()
                param.append("playerName", playerName)
                Ajax.post('mcrmb/getPlayerMcRmbInfo', param).then(res => {
                    if (res.data.code == 101) {
                        this.baseInfo = res.data.data[0]
                    }
                })
            },
            getMcrmbPlayerRecord() {
                let playerName = common.getCookie('playerName')
                if (!!!playerName) {
                    return
                }
                let param = new URLSearchParams()
                param.append("playerName", playerName)
                Ajax.post('mcrmb/getPlayerMcRmbRecord', param).then(res => {
                    if (res.data.code == 101) {
                        res.data.data.map(value => {
                            value.date = new Date(value.date * 1000).toLocaleString()
                            console.log(value)
                            this.recordData.push(value)
                        })
                    }
                })
            },
            getPlayerAllEconomyRecord() {
                let playerName = common.getCookie('playerName')
                if (!!!playerName) {
                    return
                }
                let param = new URLSearchParams()
                param.append("playerName", playerName)
                Ajax.post('economy/getPlayerAllEconomyRecord', param).then(res => {
                    if (res.data.code == 200) {
                        this.economyRecordList = res.data.list
                    }
                })
            }
        }
    }
</script>

<style lang="scss" scoped>
    .assets-info {
        .space-box {
            margin: 20px;
            font-size: 18px;
            font-weight: 700;
        }
    }
</style>
